var page_flag0=false;
var page_flag1=false;
var page_flag2=false;
var page_flag3=false;
var page_flag4=false;

var PRUN = document.getElementById("page_RUname");
var PRUP = document.getElementById("page_RUpassword");
var PQUP = document.getElementById("page_QRUpassword");
var PRUM = document.getElementById("page_RUmail");
var PRYZ = document.getElementById("page_YZ");
var PCOD = document.getElementById("code1");
var PSZC = document.getElementById("page_Registersub");

PRUN.onblur=function(){
    var re =/.{1,10}/;
    if(re.test(this.value)){
        this.style.borderColor="green";
        flag0=true;
    }else{
        this.style.borderColor="red";
        flag0=false;
    }
}
PRUP.onblur=function () {
    var g = /^\w{6,16}$/;
    if (g.test(this.value)){
        this.style.borderColor="green";
        flag1=true;
    }else{
        this.style.borderColor="red";
        flag1=false;
    }
}
PQUP.onblur=function () {
    if (this.value==RUP.value){
        this.style.borderColor="green";
        flag2=true;
    }else {
        this.style.borderColor="red";
        flag2=false;
    }
}
PRUM.onblur=function () {
    var re =/^([a-zA-Z0-9]+[_|_|\-|.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|_|.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,6}$/;
    if(re.test(this.value)){
        this.style.borderColor="green";
        flag3=true;
    }else{
        this.style.borderColor="red";
        flag3=false;
    }
}
PRYZ.onblur=function () {
    if (this.value==PCOD.value){
        this.style.borderColor="green";
        flag4=true;
    }else {
        this.style.borderColor="red";
        flag4=false;
    }
}
PSZC.onclick=function () {
    if (flag0&&flag1&&flag2&&flag3&&flag4){
        // alert("正在注册，请稍等...");
        var name = PRUM.value;
        var pwd = PRUP.value;
        var mail = PRUM.value;
        var request = ajaxFunction();
        // 2 发送请求 参数1:选择发送方式  参数2:发送地址(这里发送给一个Servlet)  参数3:是否异步传输(一般为true)
        request.open("POST", "RS", true);
        // 3 获取请求响应数据 注册监听  状态如果发生变化 会执行等号右边的函数
        request.onreadystatechange = function() {
            //前半段表示 已经能够正常处理。  再判断状态码是否是200
            if (request.readyState == 4 && request.status == 200) {
                //弹出响应的信息
                var test = eval("("+request.responseText+")");
                alert(test[0].SQLMSG);
                if (test[0].STATE){
                    GBLogin();
                }
            }
        }
        request.setRequestHeader("Content-type","application/x-www-form-urlencoded");
        request.send("Uname="+name+"&password="+pwd+"&Umail="+mail);
    }
    else{
        alert("请完整填写信息！");
    }
}

